package com.gitee.ice1938.module.admin.app.manage.appdetail;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gitee.ice1938.module.admin.app.manage.appbasetype.AppBaseTypeEntity;

/**
 * AppDetailServiceImpl
 * 
 * 
 * @author ice1938@qq.com 2019-12-2 10:38:57
 *
 */
@Service
@Transactional
public class AppDetailServiceImpl implements AppDetailService {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LoggerFactory.getLogger(AppDetailServiceImpl.class);

	@Autowired
	private AppDetailRepository appDetailRepository;
	@Autowired
	private RVersionTypeRepository rversionTypeRepository;

	@Override
	public Page<AppDetailEntity> findAppDetailData(Map<String, Object> param, Pageable pageable, Order order) {
		Page<AppDetailEntity> data = appDetailRepository.findData(param, pageable, order);
		for (AppDetailEntity appDetailEntity : data) {
			List<AppBaseTypeEntity> typeInfo = rversionTypeRepository.findTypeCodeByAppPackage(appDetailEntity.getAppPackage());
			appDetailEntity.setTypeInfo(typeInfo);
		}
		return data;
	}

	@Override
	public int insertAppDetail(AppDetailEntity data, String userLoginName) {
		// TODO Auto-generated method stub
		return appDetailRepository.insert(data, userLoginName);
	}

	@Override
	public int updateAppDetail(AppDetailEntity data, String userLoginName) {
		if (data.getTypeCode().length > 0) {
			rversionTypeRepository.deleteByPackage(data.getAppPackage());
			rversionTypeRepository.batchInsert(data.getTypeCode(), data.getAppPackage(), userLoginName);
		}

		return appDetailRepository.update(data, userLoginName);
	}

	@Override
	public int deleteAppDetailByIds(List<String> ids) {
		// TODO Auto-generated method stub
		return appDetailRepository.delete(ids);
	}

}
